//
//  ShopCarTools.m
//  News
//
//  Created by weige on 16/6/9.
//  Copyright © 2016年 weige. All rights reserved.
//


#import "ShopCarTools.h"

@implementation ShopCarTools
@synthesize goodArr;
static ShopCarTools *_intance;
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.goodArr=[NSMutableArray array];
    }
    return self;
}
+(instancetype)sharInstance
{
    
    if (_intance==nil) {

        @synchronized(self) {
               _intance=[[self alloc]init];
        }
       
        
    }
    return _intance;
}
-(void)removeShopCarProduct:(Goods *)good andIsUserFlag:(BOOL)flag
{
    for (int i=0; i<goodArr.count; i++) {
        
        if (((Goods *)goodArr[i]).ID==good.ID) {
            
          
            if (((Goods *)goodArr[i]).userBuyNumber>0) {
                if (flag==NO) {
                     ((Goods *)goodArr[i]).userBuyNumber-=1;
                }
               
            }
            if (((Goods *)goodArr[i]).userBuyNumber<=0) {
                
                 [goodArr removeObjectAtIndex:i];
            }
        }
    }
}
-(void)addShopCarProduct:(Goods *)good
{
    for (Goods *g in self.goodArr) {
        
        if (g.ID==good.ID) {
            
            return;
        }
        
    }
    [self.goodArr addObject:good];
}
@end
